package com.hb.trade.server.flow.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hb.core.pojo.flow.mapper.FlowTempNodeMapper;
import com.hb.core.pojo.flow.entity.FlowTempNode;
import com.hb.core.pojo.flow.dto.FlowTempNodeDTO;
import com.hb.trade.server.flow.service.FlowTempNodeService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 流程运行节点表(模板) 服务实现类
 * </p>
 *
 * @author zhaojk
 * @since 2021-05-27
 */
@Service
public class FlowTempNodeServiceImpl extends ServiceImpl<FlowTempNodeMapper, FlowTempNode> implements FlowTempNodeService {

    @Override
    public FlowTempNodeDTO getTempNode(Long tempMainId) {
        return _getTempNode(tempMainId, 0L);
    }

    private FlowTempNodeDTO _getTempNode(Long tempMainId, Long parentId) {
        FlowTempNodeDTO nodeDto = baseMapper.getNodeDto(tempMainId, parentId);
        // 查找下一层
        if (nodeDto != null) {
            nodeDto.setNextNode(_getTempNode(tempMainId, nodeDto.getId()));
        }
        return nodeDto;
    }

    @Override
    public List<FlowTempNodeDTO> listFlowTempNodes(Long tempMainId) {
        return baseMapper.listNodes(tempMainId);
    }
}
